package cn.scw.project.goods.controller;

import cn.scw.common.constant.SysConsts;
import cn.scw.framework.web.controller.BaseController;
import cn.scw.framework.web.domain.AjaxResult;
import cn.scw.framework.web.page.TableDataInfo;
import cn.scw.project.goods.domain.vo.GCouponUserVo;
import cn.scw.project.goods.service.IGCouponUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户优惠券Controller
 *
 * @author api
 * @date 2020-05-20
 */
@Api(tags = "用户优惠券")
@RestController
@RequestMapping(SysConsts.CONTEXT_PATH+"/goods/coupon/user")
public class GCouponUserController extends BaseController {
  @Autowired private IGCouponUserService gCouponUserService;

  @ApiOperation("查询用户优惠券列表")
  //@PreAuthorize("@ss.hasPermi('goods:user:list')")
  @GetMapping("/list/{statusCode}")
  public TableDataInfo list(@PathVariable @ApiParam("优惠券状态") String statusCode) {
    startPage();
    List<GCouponUserVo> list = gCouponUserService.selectGCouponUserList(statusCode);
    return getDataTable(list);
  }

  @ApiOperation("获取用户优惠券详细信息")
  //@PreAuthorize("@ss.hasPermi('goods:user:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return AjaxResult.success(gCouponUserService.selectGCouponUserVoById(id));
  }

  @ApiOperation("领取优惠券")
  @GetMapping("/receive")
  public AjaxResult receive(@RequestParam @ApiParam("优惠券id")Long[] ids) {
//    Long[] ids = {1L, 2L};
    gCouponUserService.receive(ids);
    return AjaxResult.success();
  }
}
